home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 40
/
Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso
/
Aminet
/
util
/
cdity
/
ModeProSrc.lha
/
Prefs
/
New
/
MPPalette.cold
< prev
next >
Wrap
Text File
|
1998-08-08
|
48KB
|
1,552 lines
#include "mpp.h"
#include <proto/gadtools.h>
#include <proto/graphics.h>
#include <clib/extras_protos.h>
#include <extras/layoutgt.h>
#include <extras/ext_text.h>
extern UBYTE ModePro[];
extern STRPTR MiscText[];
extern UBYTE filename[513];
extern struct FileRequester *PalFileReq;
/*
BOOL ReadCMAP(STRPTR Filename, struct RGB *CReg, ULONG Colors);
#define MAX_PAL_COLORS 256
/* Gad IDs */
#define PGD_PALETTE 0
#define PGD_RED 1
#define PGD_GREEN 2
#define PGD_BLUE 3
#define PGD_OK 4
#define PGD_CANCEL 5
#define PGD_RESET 6
#define PGD_UNDO 7
#define PGD_COPY 8
#define PGD_SWAP 9
#define PGD_SPREAD 10
/* Project Menu */
#define M_PALETTELOAD FULLMENUNUM(0,0,NOSUB)
#define M_PALETTESAVE FULLMENUNUM(0,1,NOSUB)
/* Bar */
#define M_PALETTEOK FULLMENUNUM(0,3,NOSUB)
#define M_PALETTECANCEL FULLMENUNUM(0,4,NOSUB)
BOOL SelectPaletteFile(UBYTE *title,UBYTE save,struct Window *Parent);
struct NewMenu PaletteMenu[]=
{
{NM_TITLE ,(STRPTR)MSG_M_PROJECT ,0 ,0,0,0},
{NM_ITEM ,(STRPTR)MSG_PRM_LOADPALETTE ,(STRPTR)MSG_PRM_LOADPALETTE_KEY ,0,0,(APTR)M_PALETTELOAD},
{NM_ITEM ,(STRPTR)MSG_PRM_SAVEPALETTE ,(STRPTR)MSG_PRM_SAVEPALETTE_KEY ,0,0,(APTR)M_PALETTESAVE},
{NM_ITEM ,NM_BARLABEL ,0 ,0,0,0},
{NM_ITEM ,(STRPTR)MSG_PRM_OK ,(STRPTR)MSG_PRM_OK_KEY ,0,0,(APTR)M_PALETTEOK},
{NM_ITEM ,(STRPTR)MSG_PRM_CANCEL ,(STRPTR)MSG_PRM_CANCEL_KEY ,0,0,(APTR)M_PALETTECANCEL},
{NM_END ,NULL ,0 ,0,0,0}
};
//extern struct Hook PaletteWinHook;
/*
struct LetterGad PReqLetters[]=
{
(STRPTR)MSG_PRG_PALETTE_KEY ,PGD_PALETTE,
(STRPTR)MSG_PRG_RED_KEY ,PGD_RED,
(STRPTR)MSG_PRG_GREEN_KEY ,PGD_GREEN,
(STRPTR)MSG_PRG_BLUE_KEY ,PGD_BLUE,
(STRPTR)MSG_PRG_RESET_KEY ,PGD_RESET,
(STRPTR)MSG_PRG_UNDO_KEY ,PGD_UNDO,
(STRPTR)MSG_PRG_COPY_KEY ,PGD_COPY,
(STRPTR)MSG_PRG_SWAP_KEY ,PGD_SWAP,
(STRPTR)MSG_PRG_SPREAD_KEY ,PGD_SPREAD,
(STRPTR)MSG_PRG_OK_KEY ,PGD_OK,
(STRPTR)MSG_PRG_CANCEL_KEY ,PGD_CANCEL,
(STRPTR)~0,~0
};
*/
extern struct Screen *Scr;
extern struct Window *Win;
extern struct TextAttr *TAttr;
extern APTR VI;
extern struct TextFont *GUIFont;
extern BOOL V39;
struct PaletteReq
{
struct Window *pr_Window;
struct LG_Control *pr_GadControl;
struct DefaultNode *pr_DefaultNode;
ULONG pr_RetVal,
pr_Mode,
pr_ModeColor;
LONG pr_RedLevel,
pr_GreenLevel,
pr_BlueLevel,
pr_RedMax,
pr_GreenMax,
pr_BlueMax;
UBYTE pr_RedBits,
pr_GreenBits,
pr_BlueBits;
WORD pr_RedMult,
pr_GreenMult,
pr_BlueMult;
UWORD pr_Colors;
UWORD pr_Offset;
struct RGB pr_Palette[MAX_PAL_COLORS];
ULONG pr_End;
ULONG pr_ActiveColor,
pr_PrevColor;
struct RGB pr_UndoBuffer[MAX_PAL_COLORS];
struct Menu *pr_MenuStrip;
BOOL pr_TrueColor;
APTR pr_VI;
WORD pr_PLeft,pr_PTop,pr_PWidth,pr_PHeight;
LONG pr_PenMap[MAX_PAL_COLORS];
//UWORD pr_PenList[MAX_PAL_COLORS];
};
#define PRM_NORMAL 0
#define PRM_COPY 1
#define PRM_SWAP 2
#define PRM_SPREAD 3
struct PaletteReq PReq={0};
void ProcessPalGads(struct IntuiMessage *IMsg);
void ProcessPalKeys(struct IntuiMessage *Imsg);
LONG LongestTextLen(struct RastPort *RP,STRPTR String, ... );
struct LG_Control *LayoutPaletteGads(struct Window *PWin, APTR PVI);
void SetPalette(void);
void UpdateSliders(void);
void GetPalette(void);
void SetUndoBuffer(void);
void GetUndoBuffer(void);
ULONG Mix(ULONG A,ULONG B, float Percent);
void ProcessPalMenus(struct DefaultNode *DN, struct Menu *MenuStrip, struct IntuiMessage *imsg);
void PGD_Cancel(void);
void PGD_Ok(void);
void PGD_Palette(LONG Active, BOOL Keyed);
void PGD_PaletteModed(LONG Active, BOOL Keyed);
void PGD_Red(LONG Value, BOOL Keyed);
void PGD_Green(LONG Value, BOOL Keyed);
void PGD_Blue(LONG Value, BOOL Keyed);
void PGD_Undo(void);
void PGD_Reset(void);
BOOL PGD_Copy(void);
BOOL PGD_Swap(void);
BOOL PGD_Spread(void);
void DrawPenBox(void);
void DrawPenRect(void);
UBYTE PenArray[MAX_PAL_COLORS];
LONG PenCount;
LONG LongestTextLen(struct RastPort *RP,STRPTR String, ... )
{
STRPTR *str;
LONG len=0,n;
str=&String;
while(*str)
{
n=StrLength(SL_TextFont ,RP->Font,
SL_String ,*str,
SL_IgnoreChars , "_",
TAG_DONE);
len=max(n,len);
str++;
}
return(len);
}
WORD MinWidth,MinHeight;
struct LG_Control *LayoutPaletteGads(struct Window *PWin, APTR PVI)
{
WORD width,height,
sliderlabellen,slidertopedge,slidernumlen,
buttontopedge,buttonheight,buttonwidth,
undobuttontopedge, undobuttonwidth,
editbuttontopedge, editbuttonwidth;
struct RastPort *rp;
struct LG_Control *pr_control;
STRPTR ok,cancel,red,green,blue,reset,undo,copy,swap,spread;
if(PVI && PWin)
{
rp=PWin->RPort;
width =PWin->Width - PWin->BorderLeft- PWin->BorderRight - 8;
height=PWin->Height - PWin->BorderTop - PWin->BorderBottom - 8 - 20;
PReq.pr_PLeft = PWin->BorderLeft + 4;
PReq.pr_PTop = PWin->BorderTop + 4;
PReq.pr_PWidth= width;
PReq.pr_PHeight= 16;
slidernumlen=MaxStrFontLen(GUIFont,4,'0','9');
buttonheight=TAttr->ta_YSize+6;
buttontopedge=height-buttonheight;
slidertopedge=buttontopedge-6-(buttonheight*3);
undobuttontopedge=slidertopedge-buttonheight-3;
editbuttontopedge=undobuttontopedge-buttonheight;
/* init strings */
ok =GetString(MSG_PRG_OK);
cancel =GetString(MSG_PRG_CANCEL);
red =GetString(MSG_PRG_RED);
green =GetString(MSG_PRG_GREEN);
blue =GetString(MSG_PRG_BLUE);
reset =GetString(MSG_PRG_RESET);
undo =GetString(MSG_PRG_UNDO);
copy =GetString(MSG_PRG_COPY);
swap =GetString(MSG_PRG_SWAP);
spread =GetString(MSG_PRG_SPREAD);
/* init lens */
buttonwidth =LongestTextLen(rp,ok,cancel,0)+8;
sliderlabellen =LongestTextLen(rp,red,green,blue,0)+8;
undobuttonwidth =LongestTextLen(rp,reset,undo,0)+8;
editbuttonwidth =LongestTextLen(rp,copy,swap,spread,0)+8;
MinHeight=buttonheight*6+6+60+PWin->BorderLeft+PWin->BorderRight+20;
MinWidth =sliderlabellen+slidernumlen+40;
MinWidth =max(MinWidth,buttonwidth*2);
MinWidth =max(MinWidth,undobuttonwidth*2);
MinWidth =max(MinWidth,editbuttonwidth*3)+PWin->BorderTop+PWin->BorderBottom;
undobuttonwidth =max(width/2,undobuttonwidth);
pr_control=LG_CreateGadgets( /* init shit */
LG_VisualInfo ,PVI,
LG_UseWindowOffsets ,PWin,
LG_EraseRemoved ,FALSE,
LG_BoundsLeft ,4,
LG_BoundsTop ,4 + 20,
LG_BoundsWidth ,width,
LG_BoundsHeight ,height,
LG_TextAttr ,TAttr,
/* Palette Gadget */
LG_GadgetKind ,PALETTE_KIND,
LG_GadgetID ,PGD_PALETTE,
LG_LeftEdge ,0,
LG_TopEdge ,0,
LG_Width ,LG_REL_WIDTH(0),
LG_Height ,editbuttontopedge-4,
LG_Flags ,PLACETEXT_ABOVE,
LG_LabelFlags ,LGLF_FITLABEL,
LG_GadgetText ,GetString(MSG_PRG_PALETTE),
LG_GadgetTags ,4,
GT_Underscore ,'_',
GTPA_Depth ,PWin->WScreen->RastPort.BitMap->Depth,
GTPA_Color ,PReq.pr_ActiveColor,
GTPA_IndicatorWidth,32,
LG_CreateGadget ,0,
/* Slider init */
LG_LeftEdge ,sliderlabellen,
LG_Width ,width-sliderlabellen-slidernumlen-8,
LG_Height ,buttonheight-2,
LG_LabelFlags ,0,
LG_Flags ,0,
/* Red Slider */
LG_GadgetKind ,SLIDER_KIND,
LG_GadgetID ,PGD_RED,
LG_TopEdge ,slidertopedge,
LG_GadgetText ,red,
LG_GadgetTags ,9,
GTSL_Level ,PReq.pr_Palette[PReq.pr_ActiveColor].Red>>24 ,
GTSL_MaxPixelLen ,slidernumlen+1,
GTSL_Min ,0,
GTSL_Max ,PReq.pr_RedMax,
GTSL_LevelFormat ,"%3ld",
GTSL_MaxLevelLen ,4,
GTSL_LevelPlace ,PLACETEXT_RIGHT,
GTSL_Justification ,GTJ_RIGHT,
GT_Underscore ,'_',
LG_CreateGadget ,0,
/* Green Slider */
LG_TopEdge ,slidertopedge+buttonheight,
LG_GadgetText ,green,
LG_GadgetTags ,9,
GTSL_Level ,PReq.pr_Palette[PReq.pr_ActiveColor].Green>>24 ,
GTSL_MaxPixelLen ,slidernumlen+1,
GTSL_Min ,0,
GTSL_Max ,PReq.pr_GreenMax,
GTSL_LevelFormat ,"%3ld",
GTSL_MaxLevelLen ,4,
GTSL_LevelPlace ,PLACETEXT_RIGHT,
GTSL_Justification ,GTJ_RIGHT,
GT_Underscore ,'_',
LG_CreateGadget ,0,
/* Blue Slider */
LG_TopEdge ,slidertopedge+buttonheight*2,
LG_GadgetText ,blue,
LG_GadgetTags ,9,
GTSL_Level ,PReq.pr_Palette[PReq.pr_ActiveColor].Blue>>24 ,
GTSL_MaxPixelLen ,slidernumlen+1,
GTSL_Min ,0,
GTSL_Max ,PReq.pr_BlueMax,
GTSL_LevelFormat ,"%3ld",
GTSL_MaxLevelLen ,4,
GTSL_LevelPlace ,PLACETEXT_RIGHT,
GTSL_Justification ,GTJ_RIGHT,
GT_Underscore ,'_',
LG_CreateGadget ,0,
/* Ok Button */
LG_GadgetTags ,1,
GT_Underscore ,'_',
LG_GadgetKind ,BUTTON_KIND,
LG_GadgetText ,ok,
LG_LeftEdge ,0,
LG_TopEdge ,buttontopedge,
LG_Width ,buttonwidth,
LG_Height ,buttonheight,
LG_CreateGadget ,0,
/* Cancel Button */
LG_LeftEdge ,LG_REL_RIGHT(-buttonwidth),
LG_GadgetText ,cancel,
LG_CreateGadget ,0,
LG_HorizCells ,2,
/* Reset Button */
LG_LeftEdge ,LG_REL_CELL_LEFTEDGE(0),
LG_TopEdge ,undobuttontopedge,
LG_Width ,LG_REL_CELL_WIDTH(1),
LG_Height ,buttonheight,
LG_GadgetText ,reset,
LG_CreateGadget ,0,
/* Undo button */
LG_LeftEdge ,LG_REL_CELL_LEFTEDGE(1),
LG_GadgetText ,undo,
LG_CreateGadget ,0,
LG_HorizCells ,3,
/* Copy */
LG_LeftEdge ,LG_REL_CELL_LEFTEDGE(0),
LG_TopEdge ,editbuttontopedge,
LG_Width ,LG_REL_CELL_WIDTH(1),
LG_GadgetText ,copy,
LG_CreateGadget ,0,
/* Swap */
LG_LeftEdge ,LG_REL_CELL_LEFTEDGE(1),
LG_GadgetText ,swap,
LG_CreateGadget ,0,
/* Spread */
LG_LeftEdge ,LG_REL_CELL_LEFTEDGE(2),
LG_GadgetText ,spread,
LG_CreateGadget ,0,
TAG_DONE);
return(pr_control);
}
return(0);
}
WORD PalWinLeft,PalWinTop,PalWinWidth,PalWinHeight;
BOOL PalFirstTime=TRUE;
BOOL PalGo;
/*
void PaletteReq(struct DefaultNode *DN)
{
struct DisplayInfo di;
struct DimensionInfo dim;
struct Requester *req;
struct Screen *pscr;
APTR pvi;
struct IntuiMessage *imsg;
STRPTR pwintitle,pwinfmt;
LONG pwinfmtlen;
WORD dripens[DRIPENS+1];
WORD swidth=320,sheight=200;
LONG l;
PalGo=TRUE;
if(PalFirstTime)
{
PalWinWidth= Win->Width/2;
PalWinHeight= Win->Height-16;
PalWinLeft= Win->LeftEdge+Win->Width/2-PalWinWidth/2;
PalWinTop= Win->TopEdge+8;
PalWinWidth= max(PalWinWidth, 150);
PalWinHeight= max(PalWinHeight,150);
PalFirstTime=FALSE;
}
pwinfmt=GetString(MSG_REQ_EDIT_PALETTE);
pwinfmtlen=strlen(pwinfmt);
if(pwintitle=AllocVec(pwinfmtlen+strlen(DN->Def_Node.ln_Name)+1,MEMF_PUBLIC|MEMF_CLEAR))
sprintf(pwintitle,pwinfmt,DN->Def_Node.ln_Name);
/*
PReq.pr_Colors=1<<DN->Depth;
PReq.pr_Colors=min(PReq.pr_Colors,MAX_PAL_COLORS);
PReq.pr_UseScreen=TRUE;
if(V39)
{
cm=pscr->ViewPort.ColorMap;
pen=0;
for(PenCount=0;PenCount<PReq.pr_Colors && pen!=-1;PenCount++)
{
PReq.pr_PenList[PenCount]=pen=ObtainPen(cm,-1,0,0,0,PEN_EXCLUSIVE|PEN_NO_SETCOLOR);
}
if(pen==-1)
{
for(Pencount--;PenCount>=0;PenCount--)
ReleasePen(cm,PReq.pr_PenList[PenCount]);
}
else
PReq.pr_UseScreen=FALSE;
}
*/
if(DN->Look3D)
{
for(l=0;l<DRIPENS;l++)
dripens[l]=DN->Pens[l];
dripens[DRIPENS]=~0;
}
else
dripens[0]=~0;
req=Busy(Win);
if(GetDisplayInfoData(0,(UBYTE *)&dim,sizeof(dim),DTAG_DIMS,DN->ModeID))
{
swidth =max(swidth ,dim.Nominal.MaxX);
sheight =max(sheight,dim.Nominal.MaxY);
}
if(pscr=OpenScreenTags(0,SA_Depth ,DN->Depth,
SA_DisplayID ,DN->ModeID,
SA_Pens ,dripens,
SA_Overscan ,OSCAN_TEXT,
SA_Width ,swidth,
SA_Height ,sheight,
SA_Title ,pwintitle,
SA_AutoScroll,TRUE,
SA_ModeProNode,DN,
TAG_DONE))
{
/*
if(drawinfo=GetScreenDrawInfo(pscr))
{
//PaletteWinHook.h_Data=drawinfo->dri_Pens[BACKGROUNDPEN];
FreeScreenDrawInfo(pscr,drawinfo);
}
*/
PReq.pr_Colors=1<<pscr->RastPort.BitMap->Depth;
PReq.pr_Colors=min(PReq.pr_Colors,MAX_PAL_COLORS);
PReq.pr_Palette[PReq.pr_Colors].Red=0;
PReq.pr_ActiveColor=0;
PReq.pr_DefaultNode=DN;
PReq.pr_Mode=0;
if(V39)
PReq.pr_RedBits = PReq.pr_GreenBits = PReq.pr_BlueBits = 8;
else
PReq.pr_RedBits = PReq.pr_GreenBits = PReq.pr_BlueBits = 4;
GetPalette();
SetUndoBuffer();
PReq.pr_PrevColor=PReq.pr_ActiveColor;
if(pvi=GetVisualInfo(pscr,0))
{
PReq.pr_VI=pvi;
if(PReq.pr_Window=OpenWindowTags(0,
WA_CustomScreen,pscr,
WA_Width ,pscr->Width,
WA_Height ,pscr->Height-pscr->BarHeight-1,
WA_Left ,0,
WA_Top ,pscr->BarHeight+1,
WA_Title ,pwintitle,
WA_MaxWidth ,-1,
WA_MaxHeight ,-1,
WA_MinWidth ,150,
WA_MinHeight ,150,
WA_IDCMP ,PALETTEIDCMP | SLIDERIDCMP | BUTTONIDCMP |
IDCMP_CLOSEWINDOW|IDCMP_NEWSIZE|IDCMP_VANILLAKEY|IDCMP_MENUPICK|IDCMP_REFRESHWINDOW,
WA_SizeGadget ,TRUE,
WA_DragBar ,TRUE,
WA_DepthGadget,TRUE,
WA_CloseGadget,TRUE,
WA_SizeBBottom,TRUE,
WA_Activate ,TRUE,
WA_NewLookMenus,TRUE,
WA_SimpleRefresh ,TRUE,
// WA_BackFill ,&PaletteWinHook,
TAG_DONE))
{
struct Process *proc;
struct Window *winptr;
proc=(struct Process *)FindTask(0);
winptr=proc->pr_WindowPtr;
proc->pr_WindowPtr=PReq.pr_Window;
if(PReq.pr_MenuStrip=CreateMenus(PaletteMenu,TAG_END))
{
if(LayoutMenus(PReq.pr_MenuStrip,pvi,
GTMN_NewLookMenus,TRUE,
TAG_END))
{
if(SetMenuStrip(PReq.pr_Window,PReq.pr_MenuStrip))
{
SetPalette();
if(GetDisplayInfoData(0,(UBYTE *)&di,sizeof(di),DTAG_DISP,DN->ModeID))
{
if(V39)
{
PReq.pr_RedBits =max(di.RedBits,1);
PReq.pr_GreenBits =max(di.GreenBits,1);
PReq.pr_BlueBits =max(di.BlueBits,1);
}
else
{
/** This needs to be fixed for V36 **/
PReq.pr_RedBits = PReq.pr_GreenBits = PReq.pr_BlueBits = 4;
/**********************************************************
PReq.pr_RedBits = sqrt(((di.PaletteRange & 0xf00) >> 8)+1);
PReq.pr_GreenBits = sqrt(((di.PaletteRange & 0xf0) >> 4)+1);
PReq.pr_BlueBits = sqrt(((di.PaletteRange & 0xf ) +1));
PReq.pr_RedBits = max(PReq.pr_RedBits ,1);
PReq.pr_GreenBits = max(PReq.pr_GreenBits ,1);
PReq.pr_BlueBits = max(PReq.pr_BlueBits ,1);
*/
}
}
PReq.pr_RedMax =(1<<PReq.pr_RedBits )-1;
PReq.pr_GreenMax =(1<<PReq.pr_GreenBits)-1;
PReq.pr_BlueMax =(1<<PReq.pr_BlueBits )-1;
PReq.pr_RedMult =255/PReq.pr_RedMax;
PReq.pr_GreenMult =255/PReq.pr_GreenMax;
PReq.pr_BlueMult =255/PReq.pr_BlueMax;
//printf("%8x %8x\n",PReq.pr_Window->RPort,GUIFont);
SetFont(PReq.pr_Window->RPort,GUIFont);
//printf("setfont\n");
if(PReq.pr_GadControl=LayoutPaletteGads(PReq.pr_Window,pvi))
{
//printf("Layout\n");
DrawPenBox();
UpdateSliders();
WindowLimits(PReq.pr_Window,MinWidth,MinHeight,-1,-1);
LG_AddGadgets(PReq.pr_Window,PReq.pr_GadControl);
while(PalGo)
{
WaitPort(PReq.pr_Window->UserPort);
while(imsg=GT_GetIMsg(PReq.pr_Window->UserPort))
{
switch(imsg->Class)
{
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh(PReq.pr_Window);
DrawPenBox();
GT_EndRefresh(PReq.pr_Window,TRUE);
break;
case IDCMP_CLOSEWINDOW:
PReq.pr_RetVal=FALSE;
PalGo=FALSE;
break;
case IDCMP_NEWSIZE:
LG_FreeGadgets(PReq.pr_GadControl);
RefreshWindowFrame(PReq.pr_Window);
{
WORD x1,y1,x2,y2;
x1=PReq.pr_Window->BorderLeft;
y1=PReq.pr_Window->BorderTop;
x2=PReq.pr_Window->Width -PReq.pr_Window->BorderRight -1;
y2=PReq.pr_Window->Height -PReq.pr_Window->BorderBottom-1;
if(x2>x1 && y2>y1)
EraseRect(PReq.pr_Window->RPort,x1,y1,x2,y2);
}
PReq.pr_GadControl=LayoutPaletteGads(PReq.pr_Window,pvi);
LG_AddGadgets(PReq.pr_Window,PReq.pr_GadControl);
UpdateSliders();
DrawPenBox();
break;
case IDCMP_MOUSEMOVE:
case IDCMP_GADGETUP:
ProcessPalGads(imsg);
break;
case IDCMP_VANILLAKEY:
ProcessPalKeys(imsg);
break;
case IDCMP_MENUPICK:
ProcessPalMenus(DN,PReq.pr_MenuStrip,imsg);
break;
}
GT_ReplyIMsg(imsg);
}
}
LG_FreeGadgets(PReq.pr_GadControl);
if(PReq.pr_RetVal)
{
FreeVec(DN->Palette);
DN->Colors=0;
if(DN->Palette=AllocVec(sizeof(struct RGB)*PReq.pr_Colors,MEMF_CLEAR|MEMF_PUBLIC))
{
DN->Colors=PReq.pr_Colors;
CopyMem(PReq.pr_Palette,DN->Palette,sizeof(struct RGB)*DN->Colors);
}
}
}
ClearMenuStrip(PReq.pr_Window);
}
}
FreeMenus(PReq.pr_MenuStrip);
}
proc->pr_WindowPtr=winptr;
CloseWindow(PReq.pr_Window);
}
FreeVisualInfo(pvi);
}
CloseScreen(pscr);
}
FreeVec(pwintitle);
/*
if(V39)
{
while(PenCount)
{
PenCount--;
ReleasePen(cm,PenArray[PenCount]);
}
}
*/
NotBusy(Win,req);
}
*/
void DrawPenBox(void)
{
// printf("DrawPenBox %x %x %d %d %d %d\n",PReq.pr_Window->RPort, PReq.pr_Window,PReq.pr_PLeft,PReq.pr_PTop,PReq.pr_PWidth,PReq.pr_PHeight );
DrawBevelBox(PReq.pr_Window->RPort,PReq.pr_PLeft,PReq.pr_PTop,
PReq.pr_PWidth,PReq.pr_PHeight ,
GTBB_Recessed, 1,
GT_VisualInfo, PReq.pr_VI,
TAG_DONE);
DrawPenRect();
}
void DrawPenRect(void)
{
// printf("DrawPenRect %x %x %d %d %d %d\n",PReq.pr_Window->RPort,PReq.pr_Window,PReq.pr_PLeft,PReq.pr_PTop,PReq.pr_PWidth,PReq.pr_PHeight );
SetAPen (PReq.pr_Window->RPort,PReq.pr_ActiveColor);
RectFill(PReq.pr_Window->RPort, PReq.pr_PLeft+2, PReq.pr_PTop+1,
PReq.pr_PLeft+PReq.pr_PWidth-3,PReq.pr_PTop+PReq.pr_PHeight-2);
}
void ProcessPalGads(struct IntuiMessage *IMsg)
{
struct Gadget *gad;
ULONG code,id;
code=IMsg->Code;
gad=(struct Gadget *)IMsg->IAddress;
id=gad->GadgetID;
switch(id)
{
case PGD_CANCEL:
PGD_Cancel();
break;
case PGD_OK:
PGD_Ok();
break;
case PGD_PALETTE:
PGD_PaletteModed(code,FALSE);
break;
case PGD_RED:
PGD_Red(code,FALSE);
break;
case PGD_GREEN:
PGD_Green(code,FALSE);
break;
case PGD_BLUE:
PGD_Blue(code,FALSE);
break;
case PGD_UNDO:
PGD_Undo();
break;
case PGD_RESET:
PGD_Reset();
break;
case PGD_COPY:
PGD_Copy();
break;
case PGD_SWAP:
PGD_Swap();
break;
case PGD_SPREAD:
PGD_Spread();
break;
}
}
void ProcessPalKeys(struct IntuiMessage *Imsg)
{
// struct LG_RetVal lgrv;
WORD direction=1;
ULONG gadid,code;
/*
lgrv=MatchKey2Gad(Imsg->Code,PReqLetters);
if(lgrv.Char & 1) direction=-1;
*/
if(LG_GadForKey(PReq.pr_GadControl,Imsg->Code,&gadid,&code))
{
if(code&1) direction=-1;
switch(gadid)
{
case PGD_PALETTE:
PGD_Palette(PReq.pr_ActiveColor+direction,TRUE);
break;
case PGD_RED:
PGD_Red(PReq.pr_RedLevel+direction,TRUE);
break;
case PGD_GREEN:
PGD_Green(PReq.pr_GreenLevel+direction,TRUE);
break;
case PGD_BLUE:
PGD_Blue(PReq.pr_BlueLevel+direction,TRUE);
break;
case PGD_RESET:
PGD_Reset();
break;
case PGD_UNDO:
PGD_Undo();
break;
case PGD_COPY:
if(PGD_Copy())
PGD_PaletteModed(PReq.pr_ActiveColor,TRUE);
break;
case PGD_SWAP:
if(PGD_Swap())
PGD_PaletteModed(PReq.pr_ActiveColor,TRUE);
break;
case PGD_SPREAD:
if(PGD_Spread())
PGD_PaletteModed(PReq.pr_ActiveColor,TRUE);
break;
case PGD_OK:
PGD_Ok();
break;
case PGD_CANCEL:
PGD_Cancel();
break;
}
}
}
void PGD_Cancel(void)
{
PalGo=FALSE;
PReq.pr_RetVal=0;
}
void PGD_Ok(void)
{
PalGo=FALSE;
PReq.pr_RetVal=1;
}
void PGD_Palette(LONG Active, BOOL Keyed)
{
if(Active<0)
Active=PReq.pr_Colors-1;
else
if(Active>=PReq.pr_Colors)
Active=0;
PReq.pr_ActiveColor=Active;
if(Keyed)
LG_SetGadgetAttrs(PReq.pr_GadControl,PGD_PALETTE,
GTPA_Color,Active,
TAG_DONE);
UpdateSliders();
}
void PGD_PaletteModed(LONG Active, BOOL Keyed)
{
if(Active<0)
Active=PReq.pr_Colors-1;
else
if(Active>=PReq.pr_Colors)
Active=0;
switch(PReq.pr_Mode)
{
case PRM_COPY:
{
ULONG color;
SetUndoBuffer();
color=PReq.pr_ModeColor;
PReq.pr_Palette[Active].Red =PReq.pr_Palette[color].Red;
PReq.pr_Palette[Active].Green =PReq.pr_Palette[color].Green;
PReq.pr_Palette[Active].Blue =PReq.pr_Palette[color].Blue;
}
break;
case PRM_SWAP:
{
ULONG color,dr,dg,db;
SetUndoBuffer();
color=PReq.pr_ModeColor;
dr=PReq.pr_Palette[color].Red;
dg=PReq.pr_Palette[color].Green;
db=PReq.pr_Palette[color].Blue;
PReq.pr_Palette[color].Red =PReq.pr_Palette[Active].Red;
PReq.pr_Palette[color].Green =PReq.pr_Palette[Active].Green;
PReq.pr_Palette[color].Blue =PReq.pr_Palette[Active].Blue;
PReq.pr_Palette[Active].Red =dr;
PReq.pr_Palette[Active].Green =dg;
PReq.pr_Palette[Active].Blue =db;
}
break;
case PRM_SPREAD:
{
ULONG l,color,c1,c2,c3,r1,r2,g1,g2,b1,b2;
float p;
color=PReq.pr_ModeColor;
SetUndoBuffer();
if(color>Active)
{
c1=Active;
c2=color;
}
else
{
c1=color;
c2=Active;
}
c3=c2-c1;
if(c3>1)
{
r1=PReq.pr_Palette[c1].Red;
g1=PReq.pr_Palette[c1].Green;
b1=PReq.pr_Palette[c1].Blue;
r2=PReq.pr_Palette[c2].Red;
g2=PReq.pr_Palette[c2].Green;
b2=PReq.pr_Palette[c2].Blue;
for(l=c1+1;l<c2;l++)
{
p=(float)(l-c1)/(float)c3;
PReq.pr_Palette[l].Red =Mix(r1,r2,p);
PReq.pr_Palette[l].Green=Mix(g1,g2,p);
PReq.pr_Palette[l].Blue =Mix(b1,b2,p);
}
}
}
break;
}
PReq.pr_Mode=PRM_NORMAL;
SetPalette();
PGD_Palette(Active,Keyed);
}
void PGD_Red(LONG Value, BOOL Keyed)
{
ULONG bitval;
if(Value>PReq.pr_RedMax)
Value=0;
else
if(Value<0)
Value=PReq.pr_RedMax;
PReq.pr_RedLevel=Value;
if(PReq.pr_PrevColor!=PReq.pr_ActiveColor)
{
SetUndoBuffer();
}
bitval=Value*PReq.pr_RedMult;
bitval=bitval | bitval << 8 | bitval << 16 | bitval <<24;
PReq.pr_Palette[PReq.pr_ActiveColor].Red=bitval;
SetPalette();
if(Keyed)
UpdateSliders();
}
void PGD_Green(LONG Value, BOOL Keyed)
{
ULONG bitval;
if(Value>PReq.pr_GreenMax)
Value=0;
else
if(Value<0)
Value=PReq.pr_GreenMax;
PReq.pr_GreenLevel=Value;
if(PReq.pr_PrevColor!=PReq.pr_ActiveColor)
{
SetUndoBuffer();
}
bitval=Value*PReq.pr_GreenMult;
bitval=bitval | bitval << 8 | bitval << 16 | bitval <<24;
PReq.pr_Palette[PReq.pr_ActiveColor].Green=bitval;
SetPalette();
if(Keyed)
UpdateSliders();
}
void PGD_Blue(LONG Value, BOOL Keyed)
{
ULONG bitval;
if(Value>PReq.pr_BlueMax)
Value=0;
else
if(Value<0)
Value=PReq.pr_BlueMax;
PReq.pr_BlueLevel=Value;
if(PReq.pr_PrevColor!=PReq.pr_ActiveColor)
{
SetUndoBuffer();
}
bitval=Value*PReq.pr_BlueMult;
bitval=bitval | bitval << 8 | bitval << 16 | bitval <<24;
PReq.pr_Palette[PReq.pr_ActiveColor].Blue=bitval;
SetPalette();
if(Keyed)
UpdateSliders();
}
void PGD_Undo(void)
{
GetUndoBuffer();
UpdateSliders();
SetPalette();
}
void PGD_Reset(void)
{
GetPalette();
UpdateSliders();
SetPalette();
}
BOOL PGD_Copy(void)
{
if( PReq.pr_Mode!=PRM_COPY)
{
PReq.pr_ModeColor=PReq.pr_ActiveColor;
PReq.pr_Mode=PRM_COPY;
return(FALSE);
}
else
return(TRUE);
}
BOOL PGD_Swap(void)
{
if( PReq.pr_Mode!=PRM_SWAP)
{
PReq.pr_ModeColor=PReq.pr_ActiveColor;
PReq.pr_Mode=PRM_SWAP;
return(FALSE);
}
else
return(TRUE);
}
BOOL PGD_Spread(void)
{
if( PReq.pr_Mode!=PRM_SPREAD)
{
PReq.pr_ModeColor=PReq.pr_ActiveColor;
PReq.pr_Mode=PRM_SPREAD;
return(FALSE);
}
else
return(TRUE);
}
void SetPalette(void)
{
if(V39)
{
LoadRGB32(&PReq.pr_Window->WScreen->ViewPort,(ULONG *)&PReq.pr_Colors);
}
else
{
UWORD palette[MAX_PAL_COLORS];
UWORD l;
for(l=0;l<PReq.pr_Colors;l++)
palette[l]=((PReq.pr_Palette[l].Red >> 20) & 0xf00) +
((PReq.pr_Palette[l].Green >> 24) & 0xf0) +
((PReq.pr_Palette[l].Blue >> 28) & 0xf);
LoadRGB4(&PReq.pr_Window->WScreen->ViewPort,palette,PReq.pr_Colors);
}
DrawPenRect();
}
void UpdateSliders(void)
{
ULONG pen;
pen=PReq.pr_ActiveColor;
PReq.pr_RedLevel=PReq.pr_Palette[pen].Red>>(32-PReq.pr_RedBits);
LG_SetGadgetAttrs(PReq.pr_GadControl,PGD_RED,
GTSL_Level,PReq.pr_RedLevel,
TAG_DONE);
PReq.pr_GreenLevel=PReq.pr_Palette[pen].Green>>(32-PReq.pr_GreenBits);
LG_SetGadgetAttrs(PReq.pr_GadControl,PGD_GREEN,
GTSL_Level,PReq.pr_GreenLevel,
TAG_DONE);
PReq.pr_BlueLevel=PReq.pr_Palette[pen].Blue>>(32-PReq.pr_BlueBits);
LG_SetGadgetAttrs(PReq.pr_GadControl,PGD_BLUE,
GTSL_Level,PReq.pr_BlueLevel,
TAG_DONE);
DrawPenRect();
}
void GetPalette(void)
{
ULONG l;
if(PReq.pr_DefaultNode->Colors && PReq.pr_DefaultNode->Palette)
{
for(l=0;l<PReq.pr_DefaultNode->Colors && l<PReq.pr_Colors;l++)
PReq.pr_Palette[l]=PReq.pr_DefaultNode->Palette[l];
}
else // Duplicate ModePro's Screen pens
{
if(V39)
{
GetRGB32(Scr->ViewPort.ColorMap,0,(ULONG)PReq.pr_Colors,(ULONG *)PReq.pr_Palette);
}
else
{
ULONG color;
struct ColorMap *cm;
cm=Scr->ViewPort.ColorMap;
for(l=0;l<PReq.pr_Colors;l++)
{
color=GetRGB4(cm,l);
PReq.pr_Palette[l].Red =(color & 0x00000f00) << 20;
PReq.pr_Palette[l].Green=(color & 0xf0) << 24;
PReq.pr_Palette[l].Blue =(color & 0xf) << 28;
}
}
}
}
void SetUndoBuffer(void)
{
ULONG colors;
colors=PReq.pr_Colors;
CopyMem(PReq.pr_Palette, PReq.pr_UndoBuffer, colors * sizeof(struct RGB));
PReq.pr_PrevColor=PReq.pr_ActiveColor;
}
void GetUndoBuffer(void)
{
ULONG colors;
struct RGB dummy[MAX_PAL_COLORS];
colors=min(PReq.pr_Colors,MAX_PAL_COLORS);
CopyMem(PReq.pr_UndoBuffer,dummy , colors * sizeof(struct RGB));
CopyMem(PReq.pr_Palette ,PReq.pr_UndoBuffer , colors * sizeof(struct RGB));
CopyMem(dummy ,PReq.pr_Palette , colors * sizeof(struct RGB));
}
ULONG Mix(ULONG A,ULONG B, float Percent)
{
float a,b,diff;
a=A;
b=B;
diff=b-a;
a+=diff*Percent;
return((ULONG) (a));
}
void ProcessPalMenus(struct DefaultNode *DN, struct Menu *MenuStrip, struct IntuiMessage *imsg)
{
UWORD menunumber,ns;
ULONG menuid;
struct MenuItem *mi;
struct RGB palette[MAX_PAL_COLORS];
menunumber=imsg->Code;
mi=ItemAddress(MenuStrip,menunumber);
if(mi)
do
{
menuid=(ULONG)(GTMENUITEM_USERDATA(mi));
switch(menuid)
{
case M_PALETTELOAD:
if(SelectPaletteFile(GetString(MSG_PRM_LOADPALETTE),0,PReq.pr_Window))
{
CopyMem(PReq.pr_Palette,palette,PReq.pr_Colors*sizeof(struct RGB));
if(ReadCMAP(filename,palette,PReq.pr_Colors))
{
SetUndoBuffer();
CopyMem(palette,PReq.pr_Palette,PReq.pr_Colors*sizeof(struct RGB));
SetPalette();
UpdateSliders();
}
}
break;
case M_PALETTESAVE:
if(SelectPaletteFile(GetString(MSG_PRM_SAVEPALETTE),1,PReq.pr_Window))
{
CopyMem(PReq.pr_Palette,palette,PReq.pr_Colors*sizeof(struct RGB));
if(!SaveCMAP(filename,palette,PReq.pr_Colors))
{
LONG error;
UBYTE errstr[91];
if(error=IoErr())
{
Fault(error,MiscText[SAVE_ERROR],errstr,90);
EZReq(PReq.pr_Window,0,ModePro,errstr,MiscText[OK],0);
}
}
}
break;
case M_PALETTEOK:
PalGo=FALSE;
PReq.pr_RetVal=1;
break;
case M_PALETTECANCEL:
PalGo=FALSE;
PReq.pr_RetVal=0;
break;
}
ns=mi->NextSelect;
mi=ItemAddress(MenuStrip,mi->NextSelect);
}while(ns!= MENUNULL && mi);
}
BOOL SelectPaletteFile(UBYTE *title,UBYTE save,struct Window *Parent)
{
WORD width;
if(!PalFileReq)
{
width=Parent->Width/2;
PalFileReq=(struct FileRequester *)AllocAslRequestTags(ASL_FileRequest,
ASLFR_TextAttr, TAttr,
ASLFR_InitialTopEdge, Parent->TopEdge+8,
ASLFR_InitialLeftEdge, Parent->LeftEdge+width/2,
ASLFR_InitialWidth, width,
ASLFR_InitialHeight, Parent->Height-16,
ASLFR_DoPatterns , TRUE,
ASLFR_InitialPattern, "#?",
ASLFR_RejectIcons, TRUE,
ASLFR_PrivateIDCMP, TRUE,
TAG_DONE);
}
if(PalFileReq)
{
if(AslRequestTags(PalFileReq,
ASLFR_Window , Parent,
ASLFR_SleepWindow , TRUE,
ASLFR_TitleText, title,
ASLFR_DoSaveMode, save,
TAG_DONE))
{
strncpy(filename,PalFileReq->fr_Drawer,512);
if(AddPart(filename,PalFileReq->fr_File,512))
return(TRUE);
}
}
return(FALSE);
}
/*
BOOL NewPaletteReq()
/*
if(drawinfo=GetScreenDrawInfo(pscr))
{
//PaletteWinHook.h_Data=drawinfo->dri_Pens[BACKGROUNDPEN];
FreeScreenDrawInfo(pscr,drawinfo);
}
*/
PReq.pr_Colors=1<<pscr->RastPort.BitMap->Depth;
PReq.pr_Colors=min(PReq.pr_Colors,MAX_PAL_COLORS);
PReq.pr_Palette[PReq.pr_Colors].Red=0;
PReq.pr_ActiveColor=0;
PReq.pr_DefaultNode=DN;
PReq.pr_Mode=0;
if(V39)
PReq.pr_RedBits = PReq.pr_GreenBits = PReq.pr_BlueBits = 8;
else
PReq.pr_RedBits = PReq.pr_GreenBits = PReq.pr_BlueBits = 4;
GetPalette();
SetUndoBuffer();
PReq.pr_PrevColor=PReq.pr_ActiveColor;
if(pvi=GetVisualInfo(pscr,0))
{
PReq.pr_VI=pvi;
if(PReq.pr_Window=OpenWindowTags(0,
WA_CustomScreen,pscr,
WA_Width ,pscr->Width,
WA_Height ,pscr->Height-pscr->BarHeight-1,
WA_Left ,0,
WA_Top ,pscr->BarHeight+1,
WA_Title ,pwintitle,
WA_MaxWidth ,-1,
WA_MaxHeight ,-1,
WA_MinWidth ,150,
WA_MinHeight ,150,
WA_IDCMP ,PALETTEIDCMP | SLIDERIDCMP | BUTTONIDCMP |
IDCMP_CLOSEWINDOW|IDCMP_NEWSIZE|IDCMP_VANILLAKEY|IDCMP_MENUPICK|IDCMP_REFRESHWINDOW,
WA_SizeGadget ,TRUE,
WA_DragBar ,TRUE,
WA_DepthGadget,TRUE,
WA_CloseGadget,TRUE,
WA_SizeBBottom,TRUE,
WA_Activate ,TRUE,
WA_NewLookMenus,TRUE,
WA_SimpleRefresh ,TRUE,
// WA_BackFill ,&PaletteWinHook,
TAG_DONE))
{
struct Process *proc;
struct Window *winptr;
proc=(struct Process *)FindTask(0);
winptr=proc->pr_WindowPtr;
proc->pr_WindowPtr=PReq.pr_Window;
if(PReq.pr_MenuStrip=CreateMenus(PaletteMenu,TAG_END))
{
if(LayoutMenus(PReq.pr_MenuStrip,pvi,
GTMN_NewLookMenus,TRUE,
TAG_END))
{
if(SetMenuStrip(PReq.pr_Window,PReq.pr_MenuStrip))
{
SetPalette();
if(GetDisplayInfoData(0,(UBYTE *)&di,sizeof(di),DTAG_DISP,DN->ModeID))
{
if(V39)
{
PReq.pr_RedBits =max(di.RedBits,1);
PReq.pr_GreenBits =max(di.GreenBits,1);
PReq.pr_BlueBits =max(di.BlueBits,1);
}
else
{
/** This needs to be fixed for V36 **/
PReq.pr_RedBits = PReq.pr_GreenBits = PReq.pr_BlueBits = 4;
/**********************************************************
PReq.pr_RedBits = sqrt(((di.PaletteRange & 0xf00) >> 8)+1);
PReq.pr_GreenBits = sqrt(((di.PaletteRange & 0xf0) >> 4)+1);
PReq.pr_BlueBits = sqrt(((di.PaletteRange & 0xf ) +1));
PReq.pr_RedBits = max(PReq.pr_RedBits ,1);
PReq.pr_GreenBits = max(PReq.pr_GreenBits ,1);
PReq.pr_BlueBits = max(PReq.pr_BlueBits ,1);
*/
}
}
PReq.pr_RedMax =(1<<PReq.pr_RedBits )-1;
PReq.pr_GreenMax =(1<<PReq.pr_GreenBits)-1;
PReq.pr_BlueMax =(1<<PReq.pr_BlueBits )-1;
PReq.pr_RedMult =255/PReq.pr_RedMax;
PReq.pr_GreenMult =255/PReq.pr_GreenMax;
PReq.pr_BlueMult =255/PReq.pr_BlueMax;
//printf("%8x %8x\n",PReq.pr_Window->RPort,GUIFont);
SetFont(PReq.pr_Window->RPort,GUIFont);
//printf("setfont\n");
if(PReq.pr_GadControl=LayoutPaletteGads(PReq.pr_Window,pvi))
{
//printf("Layout\n");
DrawPenBox();
UpdateSliders();
WindowLimits(PReq.pr_Window,MinWidth,MinHeight,-1,-1);
LG_AddGadgets(PReq.pr_Window,PReq.pr_GadControl);
while(PalGo)
{
WaitPort(PReq.pr_Window->UserPort);
while(imsg=GT_GetIMsg(PReq.pr_Window->UserPort))
{
switch(imsg->Class)
{
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh(PReq.pr_Window);
DrawPenBox();
GT_EndRefresh(PReq.pr_Window,TRUE);
break;
case IDCMP_CLOSEWINDOW:
PReq.pr_RetVal=FALSE;
PalGo=FALSE;
break;
case IDCMP_NEWSIZE:
LG_FreeGadgets(PReq.pr_GadControl);
RefreshWindowFrame(PReq.pr_Window);
{
WORD x1,y1,x2,y2;
x1=PReq.pr_Window->BorderLeft;
y1=PReq.pr_Window->BorderTop;
x2=PReq.pr_Window->Width -PReq.pr_Window->BorderRight -1;
y2=PReq.pr_Window->Height -PReq.pr_Window->BorderBottom-1;
if(x2>x1 && y2>y1)
EraseRect(PReq.pr_Window->RPort,x1,y1,x2,y2);
}
PReq.pr_GadControl=LayoutPaletteGads(PReq.pr_Window,pvi);
LG_AddGadgets(PReq.pr_Window,PReq.pr_GadControl);
UpdateSliders();
DrawPenBox();
break;
case IDCMP_MOUSEMOVE:
case IDCMP_GADGETUP:
ProcessPalGads(imsg);
break;
case IDCMP_VANILLAKEY:
ProcessPalKeys(imsg);
break;
case IDCMP_MENUPICK:
ProcessPalMenus(DN,PReq.pr_MenuStrip,imsg);
break;
}
GT_ReplyIMsg(imsg);
}
}
LG_FreeGadgets(PReq.pr_GadControl);
if(PReq.pr_RetVal)
{
FreeVec(DN->Palette);
DN->Colors=0;
if(DN->Palette=AllocVec(sizeof(struct RGB)*PReq.pr_Colors,MEMF_CLEAR|MEMF_PUBLIC))
{
DN->Colors=PReq.pr_Colors;
CopyMem(PReq.pr_Palette,DN->Palette,sizeof(struct RGB)*DN->Colors);
}
}
}
ClearMenuStrip(PReq.pr_Window);
}
}
FreeMenus(PReq.pr_MenuStrip);
}
proc->pr_WindowPtr=winptr;
CloseWindow(PReq.pr_Window);
}
FreeVisualInfo(pvi);
}
*/
*/
void PaletteReq(struct DefaultNode *DN)
{
struct DisplayInfo di;
struct DimensionInfo dim;
struct Screen *pscr;
APTR pvi;
struct IntuiMessage *imsg;
STRPTR pwintitle,pwinfmt;
LONG pwinfmtlen;
WORD dripens[DRIPENS+1];
WORD swidth=320,sheight=200;
LONG l;
pwinfmt=GetString(MSG_REQ_EDIT_PALETTE);
pwinfmtlen=strlen(pwinfmt);
if(pwintitle=AllocVec(pwinfmtlen+strlen(DN->Def_Node.ln_Name)+1,MEMF_PUBLIC|MEMF_CLEAR))
sprintf(pwintitle,pwinfmt,DN->Def_Node.ln_Name);
if(DN->Look3D)
{
for(l=0;l<DRIPENS;l++)
dripens[l]=DN->Pens[l];
dripens[DRIPENS]=~0;
}
else
dripens[0]=~0;
req=Busy(Win);
if(GetDisplayInfoData(0,(UBYTE *)&dim,sizeof(dim),DTAG_DIMS,DN->ModeID))
{
swidth =max(swidth ,dim.Nominal.MaxX);
sheight =max(sheight,dim.Nominal.MaxY);
}
if(pscr=OpenScreenTags(0,SA_Depth ,DN->Depth,
SA_DisplayID ,DN->ModeID,
SA_Pens ,dripens,
SA_Overscan ,OSCAN_TEXT,
SA_Width ,swidth,
SA_Height ,sheight,
SA_Title ,pwintitle,
SA_AutoScroll,TRUE,
SA_ModeProNode,DN,
TAG_DONE))
{
LONG colors;
colors=1<<(pscr->RastPort.BitMap->Depth);
if(!PalettePReq)
{
LONG width;
Screen
width=Win->Width/2;
PalettePReq=PR_AllocPaletteRequest(
// PR_TextAttr, TAttr,
TAG_DONE);
}
if(PalettePReq)
{
struct RGB *newpalette;
if(newpalette=AllocVec(sizeof(struct RGB)*colors,MEMF_CLEAR|MEMF_PUBLIC))
{
CopyMem(DN->Palette,newpalette,sizeof(struct RGB)*DN->Colors);
if(PR_DoPaletteRequest(PalettePReq,
PR_Screen, pscr,
PR_Colors, colors,
PR_InitialLeftEdge, 0,
PR_InitialTopEdge, pscr->BarHeight+1,
PR_InitialWidth, pscr->Width,,
PR_InitialHeight, pscr->Height-pscr->BarHeight-1,
PR_InitialPalette, newpalette,
TAG_DONE))
{
APTR dummy;
dummy=DN->Palette;
DN->Palette=newpalette;
newpalette=dummy;
DN->Colors=colors;
CopyMem(PalettePReq.pr_Palette,DN->Palette,sizeof(struct RGB)*DN->Colors);
}
FreeVec(newpalette);
}
}
CloseScreen(pscr);
}
FreeVec(pwintitle);
NotBusy(Win,req);
}